import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ichinesereader/controller/knowledgeword.dart';
import 'package:ichinesereader/pages/word/WordCardQuiz.dart';
import 'package:ichinesereader/utils/helper.dart';

import '../../themes/appTheme.dart';

class FloatingActionButtonRecycleSwitch extends StatelessWidget {
  FloatingActionButtonRecycleSwitch({
    Key? key,
  }) : super(key: key);
  final KnowledgeWordsController _controller = Get.find();

  @override
  Widget build(BuildContext context) {
    return Column(mainAxisAlignment: MainAxisAlignment.end, children: <Widget>[
      //_controller.obx((data) {
      Obx(() {
        return Visibility(
            visible: _controller.mainMode.value,
            child: SizedBox(
              height: 45,
              width: 45,
              child: FloatingActionButton(
                backgroundColor: Get.isDarkMode
                    ? Theme.of(context).primaryColorDark
                    : AppTheme.colors.pinkBtn,
                foregroundColor:
                    Get.isDarkMode ? Colors.black : AppTheme.colors.pinkBtn,
                tooltip: 'Word Quiz'.tr,
                heroTag: 'wordquiz8899',
                onPressed: () {
                  List<String>? wordIds = [];
                  _controller.knowledgeWords.forEach((word) {
                    if (word.folderId == null && word.checked!) {
                      wordIds.add(word.id!);
                    }
                  });
                  if (wordIds.length < 5) {
                    showSnackMsg("Please select no less than 5 word cards");
                    // Get.snackbar('Message'.tr,
                    //     "Please select no less than 5 word cards".tr,
                    //     backgroundColor: Get.theme.primaryColorDark,
                    //     colorText: Get.theme.primaryColorLight,
                    //     snackPosition: SnackPosition.BOTTOM);
                    return;
                  }
                  _controller.fetchWordQuiz(null, wordIds).then((data) {
                    if (data.status == 1000 && data.result != null) {
                      Get.to(() => WordCardQuiz(
                            isFromMyWords: true,
                          ));
                    }
                  });
                },
                child: Icon(
                  Icons.quiz_rounded,
                  color:
                      Get.isDarkMode ? Colors.black : AppTheme.colors.lightPink,
                  size: 24,
                ),
                elevation: 12,
              ),
            ));
      }),
      SizedBox(
        height: 9,
      ),
      SizedBox(
        height: 45,
        width: 45,
        // switch home and recycle bin
        child: Obx(() {
          return FloatingActionButton(
            backgroundColor: Get.isDarkMode
                ? Theme.of(context).primaryColorDark
                : AppTheme.colors.orangeBtn,
            foregroundColor:
                Get.isDarkMode ? Colors.black : AppTheme.colors.lightOrange,
            tooltip: _controller.mainMode.value ? 'Recycle bin'.tr : 'Home'.tr,
            heroTag: 'quizcardrecylebin8899',
            onPressed: () {
              _controller.mainMode.value = !_controller.mainMode.value;
              if (_controller.mainMode.value) {
                _controller.fetchKnowledgeFolderTree(false);
              } else {
                _controller.fetchKnowledgeWordsTrash();
              }
            },
            child: _controller.mainMode.value
                ? Icon(
                    Icons.delete_outlined,
                    color: Get.isDarkMode
                        ? Colors.black
                        : AppTheme.colors.lightOrange,
                    size: 24,
                  )
                : Icon(
                    Icons.home,
                    color: Get.isDarkMode
                        ? Colors.black
                        : AppTheme.colors.lightOrange,
                    size: 24,
                  ),
            elevation: 12,
          );
        }),
      )
    ]);
  }
}
